home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bench / client.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-04  |  4.7 KB  |  226 lines

  1. /* 
  2.  * client.c --
  3.  *
  4.  *    The client part of some multi-program synchronization primatives.
  5.  *    The routines here interface to the server; initial contact,
  6.  *    waiting for the start message, and notification of completion.
  7.  *
  8.  * Copyright 1986 Regents of the University of California
  9.  * All rights reserved.
  10.  */
  11.  
  12. #ifndef lint
  13. static char rcsid[] = "$Header: /a/newcmds/devbench/RCS/client.c,v 1.6 89/01/04 15:36:27 david Exp $ SPRITE (Berkeley)";
  14. #endif not lint
  15.  
  16.  
  17. #include "sprite.h"
  18. #include "status.h"
  19. #include "sys/ioctl.h"
  20. #include "sys/file.h"
  21. #include "stdio.h"
  22.  
  23. extern char *pdev;
  24. extern int errno;
  25.  
  26. char buffer[4096];
  27. int bufSize = sizeof(buffer);
  28.  
  29. typedef struct ClientState {
  30.     int clientStreamID;
  31. } ClientState;
  32.  
  33. /*
  34.  *----------------------------------------------------------------------
  35.  *
  36.  * ClientSetup --
  37.  *
  38.  *    Establish contact with the server.
  39.  *
  40.  * Results:
  41.  *    A pointer to state about the clients needed by ClientStart and
  42.  *    ClientDone.
  43.  *
  44.  * Side effects:
  45.  *    Creates named pipes and communicates with server
  46.  *    This exits upon error.
  47.  *
  48.  *----------------------------------------------------------------------
  49.  */
  50.  
  51. void
  52. ClientSetup(dataPtr)
  53.     ClientData *dataPtr;
  54. {
  55.     ClientState *statePtr;
  56.     ReturnStatus status;
  57.  
  58.     statePtr = (ClientState *)malloc(sizeof(ClientState));
  59.  
  60.     statePtr->clientStreamID = open(pdev, O_RDWR, 0);
  61.     if (statePtr->clientStreamID < 0) {
  62.     Stat_PrintMsg(errno, "ClientSetup: error opening pseudo device");
  63.     fflush(stderr);
  64.     exit(errno);
  65.     }
  66.     *dataPtr = (ClientData)statePtr;
  67. }
  68.  
  69. /*
  70.  *----------------------------------------------------------------------
  71.  *
  72.  * ClientRead --
  73.  *
  74.  *    Read from a pseudo-device.  The amount and number of repetitions
  75.  *    can be varied for measurment.
  76.  *
  77.  * Results:
  78.  *    None
  79.  *
  80.  * Side effects:
  81.  *    None.
  82.  *
  83.  *----------------------------------------------------------------------
  84.  */
  85.  
  86. void
  87. ClientRead(data, size, reps)
  88.     ClientData data;
  89.     int size;
  90.     int reps;
  91. {
  92.     ClientState *statePtr;
  93.     int amountRead;
  94.     ReturnStatus status;
  95.     char *buffer = (char *)malloc(size);
  96.  
  97.     statePtr = (ClientState *)data;
  98.     do {
  99.     amountRead = read(statePtr->clientStreamID, buffer, size);
  100.     if (amountRead < 0) {
  101.         Stat_PrintMsg(errno, "ClientRead: error on read");
  102.         break;
  103.     } if (amountRead != size) {
  104.         fprintf(stderr, "Short read %d < %d\n", amountRead, size);
  105.     }
  106.     } while (--reps > 0);
  107.     free(buffer);
  108. }
  109.  
  110. /*
  111.  *----------------------------------------------------------------------
  112.  *
  113.  * ClientWrite --
  114.  *
  115.  *    Write from a pseudo-device.  The amount and number of repetitions
  116.  *    can be varied for measurment.
  117.  *
  118.  * Results:
  119.  *    None
  120.  *
  121.  * Side effects:
  122.  *    None.
  123.  *
  124.  *----------------------------------------------------------------------
  125.  */
  126.  
  127. void
  128. ClientWrite(data, size, reps)
  129.     ClientData data;
  130.     int size;
  131.     int reps;
  132. {
  133.     ClientState *statePtr;
  134.     int amountWrite;
  135.     ReturnStatus status;
  136.     char *buffer = (char *)malloc(size);
  137.  
  138.     statePtr = (ClientState *)data;
  139.     do {
  140.         amountWrite = write(statePtr->clientStreamID, buffer, size);
  141.     if (amountWrite < 0) {
  142.         Stat_PrintMsg(errno, "ClientWrite: error on read");
  143.         break;
  144.     } if (amountWrite != size) {
  145.         fprintf(stderr, "Short write %d < %d\n", amountWrite,
  146.                     size);
  147.     }
  148.     } while (--reps > 0);
  149.     free(buffer);
  150. }
  151.  
  152. /*
  153.  *----------------------------------------------------------------------
  154.  *
  155.  * ClientIOControl --
  156.  *
  157.  *    Do an IOControl to a pseudo-device.
  158.  *    The amount of data passed in and number of repetitions
  159.  *    can be varied for measurment.
  160.  *
  161.  * Results:
  162.  *    None
  163.  *
  164.  * Side effects:
  165.  *    None.
  166.  *
  167.  *----------------------------------------------------------------------
  168.  */
  169.  
  170. void
  171. ClientIOControl(data, size, reps)
  172.     ClientData data;
  173.     int size;
  174.     int reps;
  175. {
  176.     ClientState *statePtr;
  177.     ReturnStatus status;
  178.     Address inBuffer = (Address)malloc(size);
  179.     Address outBuffer = (Address)malloc(size);
  180.     int foo = 27;
  181.  
  182.     statePtr = (ClientState *)data;
  183.     do {
  184.     /*
  185.     status = Fs_IOControl(statePtr->clientStreamID, foo, size, inBuffer,
  186.                 size, outBuffer);
  187.     */
  188.     if (status != SUCCESS) {
  189.         Stat_PrintMsg(status, "ClientIOControl: error ");
  190.         break;
  191.     }    } while (--reps > 0);
  192.     free(inBuffer);
  193.     free(outBuffer);
  194. }
  195.  
  196. /*
  197.  *----------------------------------------------------------------------
  198.  *
  199.  * ClientDone --
  200.  *
  201.  *    Tell the server we're done.  This is just done by closing
  202.  *    the pseudo stream.
  203.  *
  204.  * Results:
  205.  *    None
  206.  *
  207.  * Side effects:
  208.  *    None
  209.  *
  210.  *----------------------------------------------------------------------
  211.  */
  212.  
  213. void
  214. ClientDone(data)
  215.     ClientData data;
  216. {
  217.     ClientState *statePtr;
  218.     ReturnStatus status;
  219.  
  220.     statePtr = (ClientState *)data;
  221.     status = close(statePtr->clientStreamID);
  222.     if (status != SUCCESS) {
  223.     Stat_PrintMsg(status, "ClientDone: error on close");
  224.     }
  225. }
  226.